package com.ruoyi.web.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.SuperGroupProductDetail;
import com.ruoyi.system.service.ISuperGroupProductDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 拼团明细Controller
 * 
 * @author xjf
 * @date 2025-08-14
 */
@RestController
@RequestMapping("/activity/groupdetail")
public class SuperGroupProductDetailController extends BaseController
{
    @Autowired
    private ISuperGroupProductDetailService superGroupProductDetailService;

    /**
     * 查询拼团明细列表
     */
    @PreAuthorize("@ss.hasPermi('activity:groupdetail:list')")
    @GetMapping("/list")
    public TableDataInfo list(SuperGroupProductDetail superGroupProductDetail)
    {
        startPage();
        List<SuperGroupProductDetail> list = superGroupProductDetailService.selectSuperGroupProductDetailList(superGroupProductDetail);
        return getDataTable(list);
    }

    /**
     * 导出拼团明细列表
     */
    @PreAuthorize("@ss.hasPermi('activity:groupdetail:export')")
    @Log(title = "拼团明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SuperGroupProductDetail superGroupProductDetail)
    {
        List<SuperGroupProductDetail> list = superGroupProductDetailService.selectSuperGroupProductDetailList(superGroupProductDetail);
        ExcelUtil<SuperGroupProductDetail> util = new ExcelUtil<SuperGroupProductDetail>(SuperGroupProductDetail.class);
        util.exportExcel(response, list, "拼团明细数据");
    }

    /**
     * 获取拼团明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('activity:groupdetail:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(superGroupProductDetailService.selectSuperGroupProductDetailById(id));
    }

    /**
     * 新增拼团明细
     */
    @PreAuthorize("@ss.hasPermi('activity:groupdetail:add')")
    @Log(title = "拼团明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SuperGroupProductDetail superGroupProductDetail)
    {
        int result = superGroupProductDetailService.insertSuperGroupProductDetail(superGroupProductDetail);
        if (result == -1) {
            return AjaxResult.error("该用户已参团，请勿重复加入");
        }
        return toAjax(result);
    }

    /**
     * 修改拼团明细
     */
    @PreAuthorize("@ss.hasPermi('activity:groupdetail:edit')")
    @Log(title = "拼团明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SuperGroupProductDetail superGroupProductDetail)
    {
        return toAjax(superGroupProductDetailService.updateSuperGroupProductDetail(superGroupProductDetail));
    }

    /**
     * 删除拼团明细
     */
    @PreAuthorize("@ss.hasPermi('activity:groupdetail:remove')")
    @Log(title = "拼团明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(superGroupProductDetailService.deleteSuperGroupProductDetailByIds(ids));
    }
}
